package com.lagou.demo.controller;

import com.lagou.demo.service.IDemoService;
import com.lagou.edu.mvcframework.annotations.LagouAutowired;
import com.lagou.edu.mvcframework.annotations.LagouController;
import com.lagou.edu.mvcframework.annotations.LagouRequestMapping;
import com.lagou.edu.mvcframework.annotations.LagouSecurity;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@LagouController
@LagouRequestMapping("/demo")
public class DemoController {


    @LagouAutowired
    private IDemoService demoService;


    /**
     * URL: /demo/query?name=lisi&&username=joey
     * @param request
     * @param response
     * @param name
     * @return
     */
    @LagouSecurity(value = {"joey"})
    @LagouRequestMapping("/query")
    public String query(HttpServletRequest request, HttpServletResponse response,String name) throws IOException {
        response.getWriter().write("success");
        return demoService.get(name);
    }
    /**
     * @Author:丁成煜
     * create time:2021/3/16 20:57
     *  * @Param: response
     * @Param: request
     * @Param: username  用户名
     */
    @LagouSecurity(value = {"zhangsan","lisi"})
    @LagouRequestMapping("/test")
    public String test(HttpServletResponse response,HttpServletRequest request,String username) throws IOException {
        response.getWriter().write("success");
        return demoService.get(username);
    }

    @LagouSecurity(value ={"wangwu"} )
    @LagouRequestMapping("/test2")
    public String test2(HttpServletRequest request,HttpServletResponse response,String username) throws IOException {
        response.getWriter().write("this is only wangwu");
        return demoService.get(username);
    }
}
